package com.wxtl.ws.vo;

import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlElements;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

import com.wxtl.entity.UpgradePack;

@XmlType(name="data",propOrder={"success","msg","downurl","viewurl","buyurl","uplist"})
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name="data")
public class UPResult {
	private boolean success;
	private String msg="成功";
	private String downurl="/ws/downPack.action?upgradeid=";
	private String viewurl="/ws/queryPackDetail.action?upId=";
	private String buyurl="";
	@XmlElementWrapper(name="uplist")
	@XmlElements({
		@XmlElement(name="upgradePack",type=UpgradePack.class)
	})
	private List<UpgradePack> uplist=new ArrayList<UpgradePack>();

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public String getDownurl() {
		return downurl;
	}

	public void setDownurl(String downurl) {
		this.downurl = downurl;
	}

	public String getViewurl() {
		return viewurl;
	}

	public void setViewurl(String viewurl) {
		this.viewurl = viewurl;
	}

	public String getBuyurl() {
		return buyurl;
	}

	public void setBuyurl(String buyurl) {
		this.buyurl = buyurl;
	}
	
	

	
	public List<UpgradePack> getUplist() {
		return uplist;
	}

	public void setUplist(List<UpgradePack> uplist) {
		this.uplist = uplist;
	}

	public static void main(String[] args) {
		UPResult upr=new UPResult();
		UpgradePack up1=new UpgradePack();
		up1.setAuthor("hc");
		UpgradePack up2=new UpgradePack();
		List<UpgradePack> list=new ArrayList<UpgradePack>();
		list.add(up1);
		list.add(up2);
		upr.setUplist(list);
		
		JAXBContext context;
		try {
			context = JAXBContext.newInstance(UPResult.class,UpgradePack.class);
			Marshaller marshaller = context.createMarshaller();
			marshaller.setProperty(Marshaller.JAXB_ENCODING, "utf-8");
			StringWriter sw = new StringWriter();
			marshaller.marshal(upr, sw);
			System.out.println(sw.toString());
		} catch (JAXBException e) {
			System.out.println("RTMarshal转换出错");
		}
	}

}
